package dataccess

import (
	"sync"

	"github.com/go-redis/redis"
)

type RedisClient struct {
	redisClient *redis.Client
}

var (
	redisIns  *RedisClient
	redisOnce sync.Once
)

func GetInstanceRedis() *RedisClient {
	return redisIns
}

func NewRedisCli(addr, passwd string, db int) (*RedisClient, error) {
	var (
		redisCli *RedisClient
		err      error
	)
	redisOnce.Do(func() {
		redisCli = &RedisClient{
			redisClient: redis.NewClient(&redis.Options{
				Addr:     addr,
				Password: passwd,
				DB:       db,
			}),
		}

	})
	return redisCli, err
}
